<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="JQuery/jquery-1.11.1.js"></script>
<script type="text/javascript">
//创建XMLHttpRequest异步对象
function createXMLHttpRequest() {
	try {
		return new XMLHttpRequest();     //支持大多数浏览器
	} catch (e) {
        try {
			return new ActiveXObject("Msxml2.XMLHTTP");   //支持IE6.0
		} catch (e) {
			try {
				return new ActiveXObject("Microsoft.XMLHTTP");  //支持IE5.5及以下版本
			} catch (e) {
				throw e;
			}
		}
	}
}

$(function() {
	$("#btn").click(function() {
		var xmlHttp = createXMLHttpRequest();
		xmlHttp.open("GET","/ajax_project/JsonServlet",true);
		xmlHttp.send(null);
		xmlHttp.onreadystatechange = function() {
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200 ) {
				var text = xmlHttp.responseText;   //是一个JSON串
				//执行JSON串
				var person = eval("(" + text + ")");
				var str = person.name + ", " + person.age + ", " + person.sex;
				$("#h1").html(str);
			}
		}
	})
})
</script>
</head>
<body>
<h1>JSON之HelloWorld</h1>
<button id="btn">点击这里</button>
<h1 id="h1"></h1>
</body>
</html>